// TOWN SCRIPT
//    Town 1: Upper Greenleaf

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering

set_name(6,"Sal");
set_char_dialogue_pic(6,512,0);
set_name(7,"Rose");
set_char_dialogue_pic(7,524,0);
set_name(8,"Kurt");
set_char_dialogue_pic(8,1945,0);

if(get_flag(250,0) == 1) { //If night
	spawn_creature(6);
	spawn_creature(7);
	set_character_pose(6,14); 
	set_character_pose(8,14);
} else {
	erase_char(6);
	erase_char(7);
	erase_char(8);
}

set_character_pose(9,14);
set_character_pose(10,14);
set_character_pose(11,14);
set_character_pose(12,14);

set_crime_tolerance(1);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.
break;

//Barracks Stairs
beginstate 10;

	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",3);
		end();
		}
		
	reset_dialog();
	add_dialog_str(0,"This trapdoor leads back downstairs. Do you wish to climb back down?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		print_str_color("You climb downstairs",3);
		move_to_new_town (0,27,34);
	} else {
		block_entry(1);
	}
break;

//House next to Barracks
beginstate 11;
	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",3);
		end();
		}
		
	reset_dialog();
	add_dialog_str(0,"This trapdoor leads back downstairs. Do you wish to climb back down?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		print_str_color("You climb downstairs",3);
		move_to_new_town (0,30,32);
	} else {
		block_entry(1);
	}
break;

//Smiths House
beginstate 12;
	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",3);
		end();
		}	

	reset_dialog();
	add_dialog_str(0,"This trapdoor leads back downstairs. Do you wish to climb back down?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		print_str_color("You climb downstairs",3);
		move_to_new_town (0,40,33);
	} else {
		block_entry(1);
	}
break;

//Southern House
beginstate 13;
	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",3);
		end();
		}
		
	reset_dialog();
	add_dialog_str(0,"This trapdoor leads back downstairs. Do you wish to climb back down?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		print_str_color("You climb downstairs",3);
		move_to_new_town (0,34,40);
	} else {
		block_entry(1);
	}
break;

//Western House
beginstate 14;
	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",3);
		end();
		}
		
	reset_dialog();
	add_dialog_str(0,"This trapdoor leads back downstairs. Do you wish to climb back down?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		print_str_color("You climb downstairs",3);
		move_to_new_town (0,27,38);
	} else {
		block_entry(1);
	}
break;

//Inn
beginstate 15;
	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",3);
		end();
		}
		
	reset_dialog();
	add_dialog_str(0,"This trapdoor leads back downstairs. Do you wish to climb back down?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		print_str_color("You climb downstairs",3);
		move_to_new_town (0,9,38);
	} else {
		block_entry(1);
	}
break;

//Smith
beginstate 16;
	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",3);
		end();
		}
		
	reset_dialog();
	add_dialog_str(0,"This trapdoor leads back downstairs. Do you wish to climb back down?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		print_str_color("You climb downstairs",3);
		move_to_new_town (0,7,17);
	} else {
		block_entry(1);
	}
break;

//Mayors Home
beginstate 17;
	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",3);
		end();
		}
		
	reset_dialog();
	add_dialog_str(0,"This trapdoor leads back downstairs. Do you wish to climb back down?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		print_str_color("You climb downstairs",3);
		move_to_new_town (0,14,15);
	} else {
		block_entry(1);
	}
break;

//Shelves in U. Smithy
beginstate 18;
	print_str("You don't find anything useful.");
break;

//mayor's bedroom door
beginstate 19;
	if(get_flag(1,4) == 0) {
		message_dialog("You enter this bedroom, and notice that everything is covered in fine dust. Clothes have been thrown hapazardly on top of the beds. It's almost as if nobody has been in here for ages.","Actually, when you look closer, the bed on the right is dust-free, and the clothes aren't thrown - they have been carefully placed. Odd.");
		set_flag(1,4,1);
	}
break;

//beds in abandoned house
beginstate 20;
	reset_dialog();
	add_dialog_str(0,"These beds look soft and comfortable - just the thing to relax on after a hard day's work. Since nobody seems to live here, you could probably bunk down for a while and get some rest.",0);
	add_dialog_str(1,"Do you?",0);
	add_dialog_choice(0,"No.");
	add_dialog_choice(1,"Yes.");
	if(run_dialog(1) == 1) {
		end();
	} else {
		message_dialog("You lay down for a while, and eventually fall to sleep. You wake up, much rested, about 5 hours later.","");
		play_sound(20);
		set_ticks_forward(1042); //About 5 hours. ((5000/24) x 5)
		revive_party();
		end();
	}
break;

//My shelves
beginstate 21;
	message_dialog("These shelves are crammed to bursting with various books. You glance over them and see titles like _Don Quixote_, _Yes Man_ and _Alice's Adventures In Wonderland._","Towards the bottom, though, are several untitled tomes. You pull one out, and flick through it. It's full of poetry, written in neat, looped handwriting. Unfortunately, there's nothing to be learnt from it. You put it back.");
break;